/*
Copyright SecureKey Technologies Inc. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

package ledger

import (
	"strconv"

	"git.cloud.inspur.com/ichain/ichain-sdk-go/pkg/providers/ichain"
)

const (
	qsc                = "SC_QUERY"
	qscTransactionByID = "GetTransactionByID"
	qscChainInfo       = "GetChainInfo"
	qscBlockByHash     = "GetBlockByHash"
	qscBlockByNumber   = "GetBlockByNumber"
	qscBlockByTxID     = "GetBlockByTxID"
)

func createTransactionByIDInvokeRequest(chainID string, transactionID ichain.TransactionID) ichain.ContractInvokeRequest {
	var args [][]byte
	args = append(args, []byte(chainID))
	args = append(args, []byte(transactionID))

	cir := ichain.ContractInvokeRequest{
		ContractID: qsc,
		Fcn:        qscTransactionByID,
		Args:       args,
	}
	return cir
}

func createChainInfoInvokeRequest(chainID string) ichain.ContractInvokeRequest {
	var args [][]byte
	args = append(args, []byte(chainID))

	cir := ichain.ContractInvokeRequest{
		ContractID: qsc,
		Fcn:        qscChainInfo,
		Args:       args,
	}
	return cir
}

func createBlockByHashInvokeRequest(chainID string, blockHash []byte) ichain.ContractInvokeRequest {

	var args [][]byte
	args = append(args, []byte(chainID))
	args = append(args, blockHash)

	cir := ichain.ContractInvokeRequest{
		ContractID: qsc,
		Fcn:        qscBlockByHash,
		Args:       args,
	}
	return cir
}

func createBlockByNumberInvokeRequest(chainID string, blockNumber uint64) ichain.ContractInvokeRequest {

	var args [][]byte
	args = append(args, []byte(chainID))
	args = append(args, []byte(strconv.FormatUint(blockNumber, 10)))

	cir := ichain.ContractInvokeRequest{
		ContractID: qsc,
		Fcn:        qscBlockByNumber,
		Args:       args,
	}
	return cir
}

func createBlockByTxIDInvokeRequest(chainID string, transactionID ichain.TransactionID) ichain.ContractInvokeRequest {
	var args [][]byte
	args = append(args, []byte(chainID))
	args = append(args, []byte(transactionID))

	cir := ichain.ContractInvokeRequest{
		ContractID: qsc,
		Fcn:        qscBlockByTxID,
		Args:       args,
	}
	return cir
}
